package com.gzl.b2b.demo.dao;

import com.gzl.b2b.demo.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;

import java.util.List;

/**
 * user Logical Keyword Query
 * 不支持写法 ： findAllOrderByAgeDesc || findAllOrderByAge
 * Created by weican on 2019/4/13.
 */
public interface UserLogicalKeyRepository extends ElasticsearchCrudRepository<User, Long> {

    /**
     * 根据name搜索
     * sql : select * from user where name=?
     * @param name
     * @return
     */
    List<User> findByName(String name);


    /**
     * 根据 name 模糊搜索
     * sql : select * from user where name like '%?%'
     * @param name
     * @return
     */
    List<User> findByNameIsLike(String name);

    /**
     * 判断 name 是否存在
     * sql : select * from user where exists (select * from user where name=?)
     * @param name
     * @return
     */
    List<User> findByNameExists(String name);


    /**
     * 查找包括 name 的
     * sql : select * from user where name in(?)
     * @param name
     * @return
     */
    List<User> findByNameIsIn(String name);


    /**
     * 查找 name 不为空的
     * sql : select * from user where name is not null
     * @return
     */
    List<User> findByNameNotNull();


    /**
     * 查找 age 的区间结果
     * sql : select * from user where age between ? , ?
     * @param fromAge
     * @param toAge
     * @return
     */
    List<User> findByAgeBetween(Integer fromAge, Integer toAge);

    /**
     * 根据 age 排倒序
     * 不支持该写法
     * sql : select * from user order by age desc
     * @return
     */
//    List<User> findUserAllOrderByAgeDesc();

    Page<User> findAll(Sort sort);



    /**
     * 根据 name 模糊搜索后,再根据 age 排倒序
     * sql : select * from user where name like '%?%' order by age desc
     * @param name
     * @return
     */
    List<User> findByNameIsLikeOrderByAgeDesc(String name);
}
